package DataAccess;

import java.sql.*;

public class Connect{
    public  Connection conn;
    private String db;
    private String server;
    private String port;
    private String user;
    private String password;
    
    public Connect(){
        this.db = "JOGOS2016";
        this.port = "5432";
        this.server = "localhost";
        this.user = "postgres";
        this.password = "josefo1143";

        try {
            Class.forName("org.postgresql.Driver");
        } catch (java.lang.ClassNotFoundException e) {
            java.lang.System.err.print("Class Not Found Exception: Postgres Server JDBC");
            java.lang.System.err.println(e.getMessage());
            System.out.println("No JDBC Driver found in Server");
        }
        try {
            conn = DriverManager.getConnection("jdbc:postgresql://" + server + ":" + port + "/" + db, user, password);
            //System.out.println("Connection with: " + db + " !!");
        } catch (SQLException E) {
            System.out.println("SQLException: " + E.getMessage());
            System.out.println("SQLState: " + E.getSQLState());
            System.out.println("VendorError: " + E.getErrorCode());
        }
    }

    public void close(){
        try {
            conn.close();
            //System.out.println("Connection close ");
        } catch (SQLException E) {
            System.out.println("SQLException: " + E.getMessage());
            System.out.println("SQLState: "     + E.getSQLState());
            System.out.println("VendorError: "  + E.getErrorCode() + "\n Connection don't closed");
            
        }
    }
}
